<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8" import="recommenRatings.domain.*,java.util.*"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">

<%@page import="java.util.LinkedList"%><html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>RecommenRatings - Busqueda de Amigos</title>
</head>
<body>
	<form action="FrontController?res=searchUser.jsp" method="post">
	<label>Buscar</label>
	<br/>
		Nombre: <input type="text" name="name" value="<%if(request.getParameter("name")!=null){%><%=request.getParameter("name") %><%}else{out.println("Introduzca el nombre de usuario a buscar");} %>" onchange=""></input>
		<%if(request.getParameter("name")!=null){%>
		<br/>
		Sexo: <input type="radio" name="gender" value="1">Masculino <input type="radio" name="gender" value="0">Femenino <input type="radio" name="gender" value="null">Ambos
		<br/>
		Edad: Entre<input type="text" name="lowAge" value="<%if(request.getParameter("lowAge")!=null){ %><%=request.getParameter("lowAge") %><%} %>"></input> y <input type="text" name="highAge" value="<%if(request.getParameter("highAge")!=null){ %><%=request.getParameter("highAge") %><%} %>"></input> 
		<%}%>
		<br/>
		<button type="submit" name="submit" value="1">Enviar</button>
		
		
	</form>
	<%UserManager um=new UserManager();
	Collection<String> preferences=new LinkedList<String>();
	int low=0;
	if(request.getParameter("lowAge")!=null && !request.getParameter("lowAge").equals("") ){
		 low=Integer.valueOf(request.getParameter("lowAge"));
	}
	int high=200;
	if(request.getParameter("highAge")!=null && !request.getParameter("highAge").equals("") ){
		 high=Integer.valueOf(request.getParameter("highAge"));
	}
	Integer gen=null;
	if(request.getParameter("gender")!=null && !request.getParameter("gender").equals("null")){
	gen=Integer.valueOf( request.getParameter("gender"));}
	 List<User> users= um.advancedSearch(request.getParameter("name"),gen,low,high,request.getParameter("state"),request.getParameter("city"),preferences);
	%>
	<%if(request.getParameter("submit")!=null && Integer.valueOf(request.getParameter("submit"))==1){ %>
	Resultados:
	<table>
		<tr>
			<td>Nombre</td><td>Apellidos</td>
		</tr>
		<%for(User u: users){ %>
	<tr><td><%=u.getName() %></td><td><%=u.getSurname() %></td>
	</tr>
	
		<%} %>
	</table>
	<%} %><% %>
</body>
</html>